﻿#include"park.h"
#include<stdio.h>
#include<stdbool.h>
#include<Windows.h>
#include<conio.h>
char* options[] = {
	"退出"
	,	"停车场状态"
	,	"车辆到达"
	,	"车辆离开"
	//,	"dev:time-stamp"
};

bool init(void);

char plate_name_buf[PLATE_SIZE];
char date_buf[DATE_SIZE];
int main(void) {
	Car* p;
	bool result = false;
	static time_t time_temp;
	while (!init());
	int option;

	while (1) {
		system("pause");
	/*	system("cls");*/
		printf("车库容量:%d\n", capacity);
		printf("每小时需%d元\n", price_per_hour);
		for (int i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
			printf("%d %s\n", i, options[i]);
		}
		if (!scanf_s("%i", &option))
		{
			char buf[0x100];
			gets_s(buf, sizeof(buf));
			fprintf(stderr, "%s:%s\n", buf, "无效选项");
			
			continue;
		}
		switch (option)
		{
		case 0:
			printf("欢迎下次使用\n");
			return 0;
		case 1:
			printf("***已停车辆***\n");
			for (p = parking_lot.top; p; p = p->next) {
				showTimeStamp(p->startTime);
				printf("%s\n", p->name);
			}
			printf("**********\n");
			break;
		case 2:
 			p = new_car();
			result = push(&parking_lot, p);
			if (result) break;
			printf("在便道上等候......\n");
			enque(p);
			break;
		case 3:
			printf_s("车牌号：\n");
			scanf_s("%s", plate_name_buf, PLATE_SIZE);
			p = leave(plate_name_buf);
			if (!p) {
				perror("查无此车");
				break;
			}

			break;
		case 4:
			parse_stdin();
			break;
		default:
			printf("%d:无效选项\n", option);
			break;
		}
		
	}
	return 0;

}
bool init(void) {
	bool invalid = false;
	SetConsoleCP(GB2312_CHARSET);
	SetConsoleOutputCP(GB2312_CHARSET);
	do {
		printf("请输入车库容量\n");
		ASSERT_ABORT(scanf_s("%i", &capacity), "输入非数字");
		ASSERT_ABORT(capacity > 0, "容量不得为负数");
		printf("请输入每小时停车费\n");
		ASSERT_ABORT(scanf_s("%i", &price_per_hour), "输入非数字");
		ASSERT_ABORT(price_per_hour > 0, "费用不得为负数");
	} while (0);
	//struct stack {
	//	Car* top;
	//	int count;
	//}parking_lot, temp_parking_lot;

	//struct queue {
	//	Car* first;
	//	Car* last;
	//	int count;
	//}lane;

	struct stack s = { NULL,0 };
	struct queue q = { NULL,NULL ,0 };
	parking_lot = s;
	temp_parking_lot = s;
	lane = q;


	return true;
}